<?php
class sp_redis_cache_class{
	
	function sp_redis_curl($url,$request,$request_no){
		if ( strpos($url,'https') ){
			$curl = curl_init();
			curl_setopt($curl, CURLOPT_URL, $url);
			curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
			date_default_timezone_get('PRC');
			$output = curl_exec($curl);
			curl_close($curl);
		}else{
			$curl = curl_init();
			curl_setopt($curl,CURLOPT_URL,$url);
			curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
			curl_setopt($curl,CURLOPT_HEADER, 0);
			date_default_timezone_get('PRC');
			$output = curl_exec($curl);
			curl_close($curl);
		}
		if ($output == $request){
			return '<div id="message" class="updated below-h2"><p>缓存已清除!</p></div>';
		}else if ($output == $request_no){
			return '<div id="message" class="updated below-h2"><p>没有缓存可被清除</p></div>';
		}else{
			return '<div id="message" class="updated below-h2"><p>清除失败,原因:指令错误,网址错误,网络错误,服务器不支持CURL</p></div>';
		}
	}
	
	function sp_redis_check_version($local_version) {
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, 'https://6ns.net/api/sp_redis_cache_version.php');
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
		date_default_timezone_get('PRC');
		try{
			$ver = curl_exec($curl);
			curl_close($curl);
			if ( strpos($ver,'404') ){
				return '获取失败';
			}else{
				$tmp = json_decode($ver, true);
				if ($tmp['version'] != $local_version){
					return '新版本:' . $tmp['version'] . ' <a href="' . $tmp['update'] . '" target="_blank">点击此处下载新插件后,在后台安装插件-->选择ZIP安装即可</a>';
				}else if ($tmp['version'] == $local_version){
					return '目前为最新版本';
				}else{
					return '未知错误';
				}
			}
		}
		catch(Exception $e){
			return '获取失败,错误码:'.$e->getMessage();
		}
	}
}
?>